package com.wishwall.web.filters;

import java.io.IOException;
import java.util.Random;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.log4j.NDC;

/**
 *
 * @author yavor.gologanov
 *
 */
public class RequestIDFilter extends AbstractFilter {

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {

		//TODO log the raw json parameters in debug mode
		Random random = new Random();
		int newRandom = random.nextInt();
		if (newRandom < 0) {
			newRandom *= -1;
		}

		try {
			doNextFilter(request, response, chain);
		}  
		finally {
			NDC.pop();
			NDC.remove();
		}

	}

}
